<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@include file="connection.jsp"%>
<%

			String from_date = request.getParameter("from_date");
			String to_date = request.getParameter("to_date");

			String from_date_print = from_date;
			String to_date_print = to_date;

			from_date = from_date.replace("/", "-");			
			String mm = from_date.substring(0,2);
			String dd = from_date.substring(3,5);
			String yy = from_date.substring(6,10);			
			from_date = yy+"-"+mm+"-"+dd;		

			
			to_date = to_date.replace("/", "-");
			
			mm = to_date.substring(0,2);
			dd = to_date.substring(3,5);
			yy = to_date.substring(6,10);
			
			to_date = yy+"-"+mm+"-"+dd;	
			
			
%>
<%

            //HttpSession session = request.getSession();
            //session = request.getSession();

			String userid = (String) session.getAttribute("userid");

            if (userid == null) {
                response.sendRedirect("../login.jsp");
            }

            Connection c = getConnection(session);
            Statement s = c.createStatement();
            
%>

<html>
    <head>
	<link href="css/medbill.css" rel="stylesheet" type="text/css" />
	<title>PMS Home</title>
        <script language="javascript">
            function deleteUser(user){
                if(confirm("Are you sure you want to delete this user?")){
                    document.getElementById("userid").value = user;
                    document.userForm.submit();
                }
                return false;
            }
            function updateUser(userid, status){
                location = "updateUser.jsp?status="+status+"&userid="+userid;
            }
        </script>
    </head>
    
    <body>
	<table width="860" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="204" valign="top"><%@include file="header.jsp"%></td>
  </tr>
  <tr>
    <td height="30" bgcolor="#1f226f" class="headingBlue">Medical Billing and Claim Processing Professionals</td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#ccae74"><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="470" valign="top" class="txtPageTitle">Invoice Report </td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="560"></td>
              </tr>
              <tr>
                <td class="txtHomeBody"></td>
              </tr>
            </table>
              <br>        

        <b>From:</b> <%=from_date_print%> <b>To:</b> <%=to_date_print%>
        <table border="1" width="100%" style="border-collapse: collapse" bordercolor="#C0C0C0" cellspacing="1">
            <tr>
				<th height="21">Bill Id</th>
                <th >Bill Date</th>
                <th>Patient Name</th>
                <th>Date of Birth</th>
                <th>CPT Code</th>
                <th>Insurance </th>                
                <th>Comp - Amount</th>
            </tr>
            <%
			
			String query="select mast.BillId, mast.InvoiceId, date_format(mast.PostingDate,'%m/%d/%Y'), mast.PatId, mast.DiagnosisCode1, mast.DiagnosisCode2, mast.DiagnosisCode3, mast.DiagnosisCode4, mast.PatInsPrimary, sum(det.Price), patient.FirstName, patient.LastName, date_format(patient.DOB,'%m/%d/%Y'), mast.PatInsPrimary from tblbilling mast, tblbillingdetail det, tblpatientinformation patient where mast.BillId=det.BillID and patient.patientId=mast.patId and mast.DocId='"+_docCode+"' and mast.PostingDate>='"+from_date+"' and mast.PostingDate<='"+to_date+"' group by mast.BillID";
			
	    ResultSet rs = s.executeQuery(query);            
		while (rs.next()) {
            %>
            <tr>
                <td height="21">&nbsp;<%=rs.getString("mast.BillId")%></td>
                <td height="21">&nbsp;<%=rs.getString("date_format(mast.PostingDate,'%m/%d/%Y')")%></td>
                <td height="21">&nbsp;<%=rs.getString("patient.FirstName")+" "+rs.getString("patient.LastName")%></td>
                <td height="21">&nbsp;<%=rs.getString("date_format(patient.DOB,'%m/%d/%Y')")%></td>
                <td height="21"><%=rs.getString("mast.DiagnosisCode1")+ ", "+rs.getString("mast.DiagnosisCode2")+ ", "+rs.getString("mast.DiagnosisCode3")+ ", "+rs.getString("mast.DiagnosisCode4")%></td>
                <td height="21">&nbsp;<%=rs.getString("mast.PatInsPrimary")%></td>
                <td height="21">&nbsp;<%=rs.getString("sum(det.Price)")%></td>
            </tr>
            <%}%>
        </table>
        
        <p>&nbsp;</p>
        <form name="userForm" onsubmit="return validateForm();" action="users-list.jsp" method="post">
            <input type="hidden" value="" name="userid" id="userid"/>
        </form>
		<br /><br />
<br />


			  </td>
            <td width="45" valign="top">&nbsp;</td>
            <td valign="top">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="62" valign="top"><!-- #BeginLibraryItem "/Library/footer.lbi" --><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="4" bgcolor="#c7540f"></td>
      </tr>
      <tr>
        <td height="58" bgcolor="#1e2667">&nbsp;</td>
      </tr>
    </table><!-- #EndLibraryItem --></td>
  </tr>
</table>
    </body>
</html>
<%          rs.close();
            c.close();
            s.close();
%>